; Generated by Modix - Version 3.6.3 Macro A
; gen 5 macro

M300 S666 P666 			; beep 
M291 S3 R"Comissioning process" P"Press OK to continue, or CANCEL to abort"
G4 P300					; wait 300ms

M291 S2 R"Attention!" P"Check the firmware, configuration and macro file versioning in the web console. After 15 seconds the macro will resume"
echo "The firmware version is: RepRapFirmware", boards[0].firmwareVersion
echo "The configuration file is:", global.config_version
echo "The Macro file is: Version 3.6.3 Macro A"
G4 S15

if {global.generation} = 5
	if {global.idex} = 0
		M291 S3 R"Version verfication" P"According to your configuration file, you have a Generation 5 printer"
		M291 S3 R"Control board verification" P"According to your configuration file, have a single printhead setup"
	elif {global.idex} = 1
		M291 S3 R"Version verfication" P"According to your configuration file, you have a Generation 5 printer"
		M291 S3 R"Control board verification" P"According to your configuration file, have the IDEX printhead setup"
elif {global.generation} = 4
	if {global.idex} = 0
		M291 S3 R"Version verfication" P"According to your configuration file, you have a Version 4 printer"
		M291 S3 R"Control board verification" P"According to your configuration file, have a single printhead setup"
	elif {global.idex} = 1
		M291 S3 R"Version verfication" P"According to your configuration file, you have a Version 4 printer"
		M291 S3 R"Control board verification" P"According to your configuration file, have the IDEX printhead setup"

if {global.ultraprimary} = 1
	M291 S3 R"Ultra Printhead" P"According to your configuration file, you a Ultra Printhead on the Primary"
if {global.ultrasecondary} = 1
	M291 S3 R"Ultra Printhead" P"According to your configuration file, you a Ultra Printhead on the Secondary"

M291 S3 R"Verify the bed height" P"According to the guide, check that the bed is positioned so that you have some space between the probe and bed, 10mm or more is recommended."
M291 S3 R"Verify the bed height" P"If you do not have this space, check the guide on how to move the bed down"
M291 S3 R"Verify the bed height" P"Press CANCEL to abort if the bed is too high"

M564 H0 S0				; Negative movements are allowed
M561					; unload heightmap

M401					; deploy  the BLTouch probe pin
M291 S3 R"Attention!" P"Probe pin deployed. Verify the tip of the pin is lower than the nozzle. Press Cancel if it is too high"
M402 					; retract the BLTouch probe pin

M18 					; disable stepper motors
M291 S3 R"Place the printhead near the middle" P"You want to make sure there is at least 150mm of space around the printhead"

if {global.idex} = 1
	M291 S3 R"Place the secondary printhead near the middle as well" P"You want to make sure there is at least 50mm of space around the printhead"

M291 S2 R"Move to the left" P"Check the troubleshooting if it moved to the right."
G91						; relative movement
G1 H1 X-70 F700		; move 70mm to the left
M291 S3 R"Printhead moved to the left" P"Check the troubleshooting if it moved to the right."

M291 S2 R"Move to the front" P"Check the troubleshooting if it moved to the rear."
G1 H1 Y-70 F700		; Move 70mm to the front
M291 S3 R"Printhead moved to the front" P"Check the troubleshooting if it moved to the rear."

if {global.idex} = 1
	M291 S2 R"Move Secondary to the front" P"Check the troubleshooting if it moved to the rear."
	G1 H1 U-70 F700	; Move 70mm to the front
	M291 S3 R"Printhead moved to the front" P"Check the troubleshooting if it moved to the rear."

if {global.idex} = 1
	M291 S3 R"Home and Move to the front left" P"The printer will home the X axis, and then the Y axis, and then the U (secondary), then move to the front left (X100, Y100)"
else
	M291 S3 R"Home and Move to the front left" P"The printer will home the X axis, and then the Y axis, then move to the front left (X100, Y100)"

M913 X60 										; X axis 60% power


if {global.idex} = 0
	G1 H2 Z10 F200								; lift Z relative to current position
	G1 H1 X{(move.axes[0].max+5)*-1} F1200		; move quickly to X endstops and stop there (first pass)
	G1 H2 X0.5 F600      						; go back a few mm
	G1 H1 X{(move.axes[0].max+5)*-1} F300  		; move slowly to X axis endstops once more (second pass)
	G4 S1										; wait 1 second
	G1 H1 Y{(move.axes[0].max+5)*-1} F1200		; move quickly to Y endstops and stop there (first pass)
	G1 H2 Y-0.5 F600							; go back a few mm
	G1 H1 Y{(move.axes[0].max+5)*-1} F300		; move slowly to Y axis endstops once more (second pass)
elif {global.idex} = 1
	G1 H2 Z10 F200								; lift Z relative to current position
	G1 H1 X{(move.axes[0].max+5)*-1} F1200		; move quickly to X endstops and stop there (first pass)
	G1 H2 X0.5 F600								; go back a few mm
	G1 H1 X{(move.axes[0].max+5)*-1} F300		; move slowly to X axis endstops once more (second pass)
	G4 S1										; wait 1 second
	G1 H1 Y{(move.axes[1].max+5)*-1} F1200		; move quickly to Y endstops and stop there (first pass)
	G1 H2 Y-0.5 F600							; go back a few mm
	G1 H1 Y{(move.axes[1].max+5)*-1} F300		; move slowly to Y axis endstops once more (second pass)
	G1 H1 U{(move.axes[3].max+5)} F1200			; move quickly to U endstops and stop there (first pass)
	G1 H2 U-0.5 F600      						; go back a few mm
	G1 H1 U{(move.axes[3].max+5)}  F300  		; move slowly to U axis endstops once more (second pass)


M913 X100 										; X axis 100% power
G4 P0											; wait for movement to complete

M291 S3 R"Move to the front left" P"The primary printhead will now move to the front left (X100, Y100)"
G90						; absolute movements
G1 X100 Y100 F2000		; move to the front left

M558 F10 T1000			; reduce probing speed significantly
G4 P0					; wait for movement to complete
M291 S2 R"BLTouch test" P"The BLTouch probe will deploy, and the bed will slowly move up. Using your hands, trigger the BLTouch probe and verify that the bed stops moving"
M291 S2 R"BLTouch test" P"If the bed does not stop moving, immediatly shut the printer down!"
M291 S2 R"BLTouch test" P"Press OK to start the bed probing"

G30 S-1					; probe the bed
M558 F120 T6000			; back to default settings

M291 S2 R"BLTouch test" P"The printer will now home the Z axis, using the normal BLTouch probing speed"
G30						; probe the bed
G4 P0					; wait for movement to complete
G91
G1 Z10					; move the nozzle up 10mm
G90

M291 S2 R"Bed placement verification" P"The printer will first then move to the X axis minimum, then to the X axis maximum"
M291 S2 R"Bed placement verification" P"Verify that the BLTouch is posisioned above the bed in both cases"
M291 S2 R"Bed placement verification" P"Press OK to move to the left"

G1 H1 X{move.axes[0].min+0.2} Y40 F3000	; move printhead to the left side of the bed; stop if it hits the endstop.
M300 S1111 P666			; beep 
G4 P0					; wait for movement to complete
M291 S2 R"Left side" P"Verify that the BLTouch and nozzle are positioned above the bed. If they are not above the bed, adjust the bed." ;
M291 S2 R"Bed placement verification" P"Press OK to move to the right"

G1 X{move.axes[0].max-0.2} Y40 F3000	; move printhead to the right side of the bed
M300 S1111 P666 		; beep 
G4 P0					; wait for movement to complete
M291 S2 R"Right side" P"Verify that the BLTouch and nozzle are positioned above the bed. If they are not above the bed, adjust the bed." ;

M564 S1 H1				; Disable negative movements
G4 P0					; wait for movement to complete
M291 S2 R"You may proceed to the next step" P"Initialization has been completed"
M18						; release stepper motors